package Arrays;

/**
 * 作者:hfj
 * 功能:35.搜索插入位置
 * 日期: 2025/10/20 16:43
 */
public class SearchInsert {
    public static void main(String[] args) {
        int[] nums = {1,3,5,6};
        int target = 7;
        System.out.println(searchInsert(nums,target));
    }

    public static int searchInsert(int[] nums, int target) {
        int index = 0;
        //用目标值判断，如果大于数组就指针加加，没有直接返回
        for (int i = 0; i < nums.length; i++) {
            if (target > nums[i]){
                index++;
            }else {
                return index;
            }
        }
        return index;
    }
}
